// import urlConfig from './config.js'
const request = {}
const headers = {}
import Vue from 'vue'

request.globalRequest = (url, method, data, power) => {
	var localHttp = Vue.prototype.$http_url.getHttpUrl();
	

	var header = null
	if(power == 1){
		header = {
			"Content-Type": "application/x-www-form-urlencoded", //自定义请求头信息
		}
	}else if(power == 2){
		header = {
			"Content-Type":"application/json", //自定义请求头信息
		}
	}
	

	if (method == "POST") {
		return uni.request({
			url: localHttp + url,
			dataType: "json",
			header: header,
			method: method,
			data: data,
		}).then(res => {

			if (res[0]!=null && res[0].errMsg.length > 0) {
				uni.showToast({
					title: "网络异常！"
				})
				return;
			}
			if (res[1].statusCode && res[1].statusCode == 200) {
				return res[1];
			}else{
				throw res
			}
			
			
		})
		.catch(parmas => {
			return Promise.reject(parmas)
		})

	} else if (method == "GET") {
		
		var curUrl = localHttp + url

		return uni.request({
			url: curUrl,
			header: header,
			method: method,
			data: data,
		}).then(res => {
			if (res[0]!=null && res[0].errMsg.length > 0) {
				uni.showToast({
					title: "网络异常！"
				})
				return;
			}
			if (res[1].statusCode && res[1].statusCode == 200) {
				return res[1];
			}else{
				throw res
			}

		}).catch(parmas => {
			return Promise.reject(parmas)
		})

	}




}

export default request
